<?php
/**
 * 用户逻辑层
 *
 */
namespace App\Dao;

use App\Model\BaseModel;

class AdminUser extends Common
{
    const model = 'App\Model\JwAdminUser';

    /***
     * 获取用户详情
     * @param string $user_name
     * @param string $password
     * @return mixed
     */
    public static function getAdminDetailByName(string $user_name,?array $with = []){
        $model = new BaseModel(self::model);
        return $model->getInstance()
            ->where('user_name',$user_name)
            ->with($with)
            ->select(['last_ip','user_name','email','ec_salt','role_id','password','user_id'])
            ->first();
    }

    /***
     * 获取用户详情
     * @param string $user_id
     * @return mixed
     */
    public static function getAdminDetailById(int $user_id,?array $with = []){
        $model = new BaseModel(self::model);
        return $model->getInstance()
            ->where('user_id',$user_id)
            ->with($with)
            ->select(['last_ip','user_name','email','role_id','user_id','ec_salt','password'])
            ->first();
    }

    /**
     * 修改用户信息
     * @param array $where
     * @param array $data
     * @return \Hyperf\Utils\Collection
     */
    public static function updateUsers(array $where, array $data){
        $model = new BaseModel(self::model);
        return $model->updateModel($where,$data);
    }
}
